package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.Address;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class AddressDao extends BaseDao<Address> {

    public List<Address> page(Map<String, Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from address where 1=1");

        String sql = sbStr.toString();
        return this.queryList(sql, paramList, Address.class, splitPage);
    }

    public List<Address> list(Map<String, Object> paraMap) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from address where 1=1");

        if (StringEx.isNotNull(paraMap.get("userId"))) {
            sbStr.append(" and userId = ? ");
            paramList.add(paraMap.get("userId"));
        }
        if (StringEx.isNotNull(paraMap.get("status"))) {
            sbStr.append(" and status = ? ");
            paramList.add(paraMap.get("status"));
        }

        String sql = sbStr.toString();
        return this.queryList(sql, new ArrayList<>(), Address.class);
    }

    public List<Address> listByUserId(Integer userId) {
        StringBuilder sbStr = new StringBuilder("select * from address");
        sbStr.append(" where userId = "+ userId +" ");

        String sql = sbStr.toString();
        return this.queryList(sql, new ArrayList<>(), Address.class);
    }
}
